@extends('layouts.frontend-iframe-base')


@section('css')
@stop

@section('content')
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            个人中心
            <small>导出数据</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">首页</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">

                <div class="box">
                    {{--<label>数据导出最多2000条</label>--}}
                    <div class="box-body">
                        <div class="row" style="margin-bottom: 20px">
                            <div class="col-sm-9">
                                <form class="form-inline">
                                    <div class="form-group">
                                        <label>设备编号</label>

                                        <input type="text" class="form-control J-id">

                                    </div>
                                    <div class="form-group">
                                        <label>选择时间</label>
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="form-control" id="reservation">
                                        </div>
                                    </div>
                                    <button type="button" class="btn btn-default J-search">搜索</button>
                                </form>

                            </div>
                            <div class="col-sm-3">
                                <button type="button" class="btn btn-info pull-right J-export" style="">导出excel
                                </button>
                            </div>
                        </div>
                        <div>
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        {{--'字段','设备编号','直流电压1','直流电流1','直流电压2','直流电压2','直流电压3','直流电压3','直流电压4','直流电压4',--}}
                                        {{--'交流A相电压','交流A相电流','交流B相电压','交流B相电流','交流C相电压','交流C相电流','逆变器温度','TotGenCap','逆变器状态','IVError','IVMode','电网频率','IVRun',--}}
                                        {{--'年发','月发','上个月发','日发','昨天发',--}}
                                        {{--'PowerLimitPercent','有功功率','无功功率',--}}
                                        {{--'视在功率','功率因素','板测温度1','板测温度2',--}}
                                        {{--'IVType','EventTime','EventType'--}}
                                        <th>id</th>
                                        <th>设备编号</th>
                                        <th>发生时间</th>
                                        <th>直流电压1</th>
                                        <th>直流电流1</th>
                                        <th>直流电压2</th>
                                        <th>直流电流2</th>
                                        <th>直流电压3</th>
                                        <th>直流电流3</th>
                                        <th>直流电压4</th>
                                        <th>直流电流4</th>
                                        <th>交流A相电压</th>
                                        <th>交流A相电流</th>
                                        <th>交流B相电压</th>
                                        <th>交流B相电流</th>
                                        <th>交流C相电压</th>
                                        <th>交流C相电流</th>
                                        <th>逆变器温度</th>
                                        <th>总发</th>
                                        <th>逆变器状态</th>
                                        <th>电网频率</th>
                                        <th>年发</th>
                                        <th>月发</th>
                                        <th>上月发</th>
                                        <th>日发</th>
                                        <th>昨日发</th>
                                        <th>有功功率</th>
                                        <th>无功功率</th>
                                        <th>视在功率</th>
                                        <th>功率因素</th>
                                        <th>板测温度</th>

                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($data as $k=>$obj)
                                        <tr>
                                            <th scope="row">{{$k+1}}</th>
                                            <td>{{$obj->device_id}}</td>
                                            <td>{{$obj->EventTime}}</td>
                                            <td>{{$obj->DCU1}}</td>
                                            <td>{{$obj->DCI1}}</td>
                                            <td>{{$obj->DCU2}}</td>
                                            <td>{{$obj->DCI2}}</td>
                                            <td>{{$obj->DCU3}}</td>
                                            <td>{{$obj->DCI3}}</td>
                                            <td>{{$obj->DCU4}}</td>
                                            <td>{{$obj->DCI4}}</td>
                                            <td>{{$obj->ACUA}}</td>
                                            <td>{{$obj->ACIA}}</td>
                                            <td>{{$obj->ACUB}}</td>
                                            <td>{{$obj->ACIB}}</td>
                                            <td>{{$obj->ACUC}}</td>
                                            <td>{{$obj->ACIC}}</td>
                                            <td>{{$obj->IVTemp}}</td>
                                            <td>{{$obj->TotGenCap}}</td>
                                            <td>{{$obj->IVStatus}}</td>
                                            <td>{{$obj->FR}}</td>
                                            <td>{{$obj->YearGenCap}}</td>
                                            <td>{{$obj->MonthGenCap}}</td>
                                            <td>{{$obj->LastMonthGenCap}}</td>
                                            <td>{{$obj->DayGenCap}}</td>
                                            <td>{{$obj->LastDayGenCap}}</td>
                                            <td>{{$obj->ActivePower}}</td>
                                            <td>{{$obj->ReactivePower}}</td>
                                            <td>{{$obj->ApparentPower}}</td>
                                            <td>{{$obj->PowerFactor}}</td>
                                            <td>{{$obj->BoardTemp1}}</td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                                {{$data->links()}}
                            </div>
                        </div>

                    </div>

                </div>

            </div>
        </div>
    </section>
    <!-- /.content -->


@stop

@section('js')
    <script>
        $(function () {

//            $('#J-form').ajaxForm({
//                beforeSubmit: function (data) {
//                    if (data[1].value != data[2].value) {
//                        alert('两次密码不一致！');
//                        return false;
//                    }
//                    validator_info_clear($('#J-form'));
//                },
//                success: function (data) {
//                    if (data.status == 1) {
//                        alert('修改成功！');
//                        window.location.href = '/frontend/user/profile';
//                    } else {
//                        alert(data.error_msg);
//                    }
//                },
//                error: function (xhr) {
//                    validator_info_show($('#J-form'), xhr);
//                }
//            });


            $(".J-search").on('click',function(){
                var id = $(".J-id").val();
                var start = !$('#reservation').val() ? '' : $('#reservation').data('daterangepicker').startDate.format('YYYY-MM-DD HH:mm:ss');
                var end = !$('#reservation').val() ? '' : $('#reservation').data('daterangepicker').endDate.format('YYYY-MM-DD HH:mm:ss');
                window.location.href = encodeURI('/frontend/user/export-data?id=' + id + '&from_time=' + start
                    + '&to_time=' + end);
            });

            $(".J-export").on('click',function(){
                var id = $(".J-id").val();
                var start = !$('#reservation').val() ? '' : $('#reservation').data('daterangepicker').startDate.format('YYYY-MM-DD HH:mm:ss');
                var end = !$('#reservation').val() ? '' : $('#reservation').data('daterangepicker').endDate.format('YYYY-MM-DD HH:mm:ss');

//                $.get('/frontend/user/export?',{
//                    id: id,
//                    from_time: start,
//                    to_time: end
//                }).success(function(d){
//                    console.log(d);
//                })

                window.open('/frontend/user/export?id=' + id + '&from_time=' + start
                + '&to_time=' + end)
            });

            var json = {};
            if(getP('from_time')){
                json = {
                    format:"YYYY-MM-DD HH:mm:ss",
                    "timePicker": true,
                    "timePicker24Hour": true,
                    "timePickerIncrement": 1,
                    "timePickerSeconds": true,
                    "startDate": getP('from_time'),
                    "endDate": getP('to_time')
                };
                $("#reservation").val(getP('from_time') + ' - ' + getP('to_time'));

            } else {
                json = {
                    format:"YYYY-MM-DD HH:mm:ss",
                    "timePicker": true,
                    "timePicker24Hour": true,
                    "timePickerIncrement": 1,
                    "timePickerSeconds": true
                };
            }


            $('.J-id').val(getP('id') || '');
            $("#reservation").daterangepicker(json);

            /**
             * 获取URL参数
             * @param name
             * @returns {*}
             */
            function getP(name){
                var url = decodeURI(window.location.href);
                if (url.indexOf("?") != -1) {
                    var str = url.split('?')[1];
                    var strs = str.split("&");

                    for(var i = 0;i < strs.length; i++){
                        if(strs[i].split('=')[0] == name){
                            return strs[i].split('=')[1]
                        }
                    }

                }

                return '';
            }


        });


    </script>
@stop